home *** CD-ROM | disk | FTP | other *** search
- Path: gail.ripco.com!mambuhl
- From: mambuhl@ripco.com (Martin Ambuhl)
- Newsgroups: comp.lang.c
- Subject: Re: read/write integers t
- Date: 7 Mar 1996 10:50:26 GMT
- Organization: Ripco Communications, Inc.
- Message-ID: <4hmf1i$k1k@gail.ripco.com>
- NNTP-Posting-Host: cook.ripco.com
-
- Jason Collins <jason@www.inia.net.au> in <313EBF65.4E82@www.inia.net.au>
- asks:
-
- >My problem is that I'm trying to write a program that will read an integer from
- >the file
- >count.dat, increment the integer then write it back to count.dat. I have provi
- >ed the listing so
- >that you can all tell me what I'm doing wrong.
-
- >Thanks....and.....be gentle.
-
- As usual, my comments and changes are marked with `/* mha - ... */'.
-
- #include <stdio.h>
- #include <stdlib.h>
-
- FILE *filePtr;
-
- int /* mha - was `void' */ main()
- {
- int /* mha - was `char' */ ctr;
-
- filePtr = fopen("count.dat", "rb"); /* mha - was "ab" */
- fscanf(filePtr, "%d", &ctr);
- fclose(filePtr);
-
- ctr++;
-
- filePtr = fopen("count.dat", "wb");
- fprintf(filePtr, "%d", ctr);
- fclose(filePtr);
- return 0; /* mha - added explicit return value */
- }
-
-
- --
- * Martin Ambuhl net: mambuhl@ripco.com
- * Chicago, IL (USA)
-